class ListHelper:

    @staticmethod
    def find_all(list_target, func):
        for item in list_target:
            if func(item):
                yield item

    @staticmethod
    def find_item_property(list_target, func):
        for item in list_target:
            yield func(item)

    @staticmethod
    def sum_item_property(list_target, func):
        list_sum = 0
        for item in list_target:
            list_sum += func(item)
        return list_sum

    @staticmethod
    def find_first_condition(list_target, func):
        for item in list_target:
            if func(item):
                return item

    @staticmethod
    def find_end_condition(list_target, func):

        for index in range(len(list_target), 0, -1):
            if func(list_target[index - 1]):
                return list_target[index - 1]

    @staticmethod
    def delete_condition(list_target, func):
        for index in range(len(list_target) - 1, -1, -1):
            if func(list_target[index]):
                item = list_target[index]
                del list_target[index]
                yield item

    @staticmethod
    def find_max_condition(list_target, func):
        max_item = list_target[0]
        for item in list_target:
            if func(item) > func(max_item):
                max_item = item
        return max_item

    @staticmethod
    def find_min_condition(list_target, func):
        min_item = list_target[0]
        for item in list_target:
            if func(item) < func(min_item):
                min_item = item
        return min_item

    @staticmethod
    def sort_condition(list_target, func, reverse=False):
        for i in range(0, len(list_target) - 1):
            for j in range(i + 1, len(list_target)):
                if not reverse:
                    if func(list_target[i]) > func(list_target[j]):
                        list_target[i], list_target[j] = list_target[j], list_target[i]
                else:
                    if func(list_target[i]) < func(list_target[j]):
                        list_target[i], list_target[j] = list_target[j], list_target[i]
        return list_target

    @staticmethod
    def sort_condition2(list_target, func):
        for i in range(0, len(list_target) - 1):
            for j in range(i + 1, len(list_target)):
                if func(list_target[i], list_target[j]):
                    list_target[i], list_target[j] = list_target[j], list_target[i]

        return list_target
